#!/bin/bash

echo "=== 多模块项目API测试脚本 ==="
echo "请确保所有服务都已启动"
echo ""

# 等待服务启动
echo "等待服务启动..."
sleep 10

# 测试用户服务
echo "=== 测试用户服务 ==="
echo "1. 创建用户..."
USER_RESPONSE=$(curl -s -X POST http://localhost:9090/api/users \
  -H "Content-Type: application/json" \
  -d '{"username":"testuser","email":"test@example.com","phone":"13800138000"}')
echo "响应: $USER_RESPONSE"

echo ""
echo "2. 获取所有用户..."
curl -s http://localhost:9090/api/users | jq '.'

echo ""
echo "3. 获取用户ID为1的用户..."
curl -s http://localhost:9090/api/users/1 | jq '.'

echo ""
echo "=== 测试订单服务 ==="
echo "1. 创建订单..."
ORDER_RESPONSE=$(curl -s -X POST http://localhost:9090/api/orders \
  -H "Content-Type: application/json" \
  -d '{"userId":1,"amount":99.99,"status":"PENDING"}')
echo "响应: $ORDER_RESPONSE"

echo ""
echo "2. 获取所有订单..."
curl -s http://localhost:9090/api/orders | jq '.'

echo ""
echo "3. 获取用户ID为1的订单..."
curl -s http://localhost:9090/api/orders/user/1 | jq '.'

echo ""
echo "=== 测试完成 ==="
echo "可以通过以下地址访问H2控制台查看数据库:"
echo "用户服务: http://localhost:9091/h2-console"
echo "订单服务: http://localhost:9092/h2-console"
echo "数据库连接信息:"
echo "  JDBC URL: jdbc:h2:mem:userdb (用户服务) / jdbc:h2:mem:orderdb (订单服务)"
echo "  用户名: sa"
echo "  密码: (空)"
